# from tkinter import StringVar, DISABLED, PhotoImage, HORIZONTAL
# from tkinter.messagebox import showinfo
# from tkinter.tix import Tk
# from tkinter.ttk import Label, Entry, Button, Scale
# import pyperclip
#
#
# class IdCheck:
#     """身份证18位 = 地区码6+出生日期码8+顺序码3+校验码1"""
#
#     def __init__(self, id_number):
#         # self.area_list = []
#         self.address_file_path = './data/id_area.txt'
#         self.return_data = {
#             "valid": '',
#             'sex': '',
#             'date': '',
#             'area': ''
#         }
#         self.area_list = []
#         self.id_number = id_number
#         self.init_address()
#
#     def Verification_ID_card(self):
#         check_code_xi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]  # 每个位上乘的系数列表
#         check_code = ["1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2"]  # 返回的校验码列表
#         tmp_sum = sum([int(self.id_number[:17][i]) * check_code_xi[i] for i in range(len(check_code_xi))])
#         check_code = check_code[tmp_sum % 11]
#         if check_code == self.id_number[17]:
#             self.return_data['valid'] = '有效'
#             self.return_data['sex'] = "女" if int(self.id_number[14:17][2]) % 2 == 0 else "男"
#             self.return_data['date'] = self.id_number[6:10] + "年" + self.id_number[10:12] + "月" + self.id_number[
#                                                                                                   12:14] + "日"
#             self.return_data['area'] = self.get_address()
#         else:
#             self.return_data['valid'] = '无效'
#         return self.return_data
#
#     def init_address(self):
#         try:
#             with open(file=self.address_file_path, mode="r", encoding="UTF-8") as f:
#                 lines = f.readlines()
#         except Exception as e:
#             showinfo("系统提醒", f"地区文件读取失败!\n{e}")
#         [self.area_list.append(line.split(",")) for line in lines]
#
#     def get_address(self):
#         area_code = self.id_number[:6]
#         address = [i[1] for i in self.area_list if i[0] == area_code][0]
#         pyperclip.copy(address)
#         return address
#
#
# class IDCheckGUI(Tk):
#     def __init__(self):
#         super().__init__()
#         # 数据参数定义
#         self.login_image = PhotoImage(file="./img/left.png")
#         self.var_input = StringVar()
#         self.var_valid = StringVar()
#         self.var_sex = StringVar()
#         self.var_date = StringVar()
#         self.var_area = StringVar()
#         # 窗体设置+数据参数及方法绑定
#         self.title("身份证信息校验系统")
#         self.iconbitmap('./img/title.ico')
#         self.geometry("727x472+10+10")  # w*h+x+y
#         self.resizable(0, 0)
#         self["bg"] = "whitesmoke"
#         self.setup_UI()
#
#     def setup_UI(self):
#         font10 = ("微软雅黑", 10, "bold")
#         font18 = ("微软雅黑", 18, "bold")
#         x = [350, 430]
#         y = [170, 165]
#         w, h = 60, 38
#         # 左侧图片
#         Label(self, image=self.login_image).place(x=5, y=5)
#         # 输入信息
#         Label(self, text="请输入身份证号码:", font=font10).place(x=x[0], y=20)
#         Entry(self, textvariable=self.var_input, font=font18).place(x=x[0], y=70)
#         # 验证按钮
#         Button(self, text="校验", command=self.get_info).place(x=660, y=70, width=60, height=38)
#         # 具体信息
#         Label(self, text="是否有效：").place(x=x[0], y=y[0])
#         Entry(self, state=DISABLED, textvariable=self.var_valid, font=font10).place(x=x[1], y=y[1], width=w)
#         Label(self, text="性     别：").place(x=x[0], y=y[0] + 50)
#         Entry(self, state=DISABLED, textvariable=self.var_sex, font=font10).place(x=x[1], y=y[1] + 50, width=w)
#         Label(self, text="出生日期：").place(x=x[0], y=y[0] + 50 * 2)
#         Entry(self, state=DISABLED, textvariable=self.var_date, font=font10).place(x=x[1], y=y[1] + 50 * 2,
#                                                                                    width=w + 140)
#         Label(self, text="所  在  地：").place(x=x[0], y=y[0] + 50 * 3)
#         Entry(self, textvariable=self.var_area, font=font10).place(x=x[1], y=y[1] + 50 * 3, width=w + 230)
#         Label(self, text="透  明  度：").place(x=x[0], y=y[0] + 50 * 4)
#         Scale(self, from_=0, to=0.9, orient=HORIZONTAL, command=self.set_alpha).place(x=x[1], y=y[1] + 50 * 4)
#
#     def set_alpha(self, v):
#         self.attributes("-alpha", 1 - float(v))
#
#     def get_info(self):
#         id_number = self.var_input.get()
#         if len(id_number) == 18:
#             id_check = IdCheck(id_number)
#             r_data = id_check.Verification_ID_card()
#             self.var_valid.set(r_data['valid'])
#             self.var_sex.set(r_data['sex'])
#             self.var_date.set(r_data['date'])
#             self.var_area.set(r_data['area'])
#         else:
#             showinfo("系统消息", "输入的身份证号码不是18位，请重新输入！")
#
#
# if __name__ == '__main__':
#     check_gui = IDCheckGUI()
#     check_gui.mainloop()
